<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>title</title>
	<link rel="stylesheet" type="text/css" href="../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>

	<header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
		<a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
			<span class="aui-iconfont aui-icon-left"></span>
		</a>
		<div class="aui-title" id="title">
			物料列表
		</div>
	</header>

	<script id="mrlTemp" type="text/x-dot-template">

		{{~ it:value:index}}
		<li class="aui-list-item" onclick="setMrl('{{= it[index].mrlId }}','{{= it[index].mrlCode }}','{{= it[index].mrlName }}');">
			<div class="aui-list-item-inner">
				<div class="aui-list-item-title">{{= it[index].mrlCode }}:{{= it[index].mrlName }}</div>
			</div>
		</li>
		{{~}}

	</script>

	<div class="aui-content">
		<div class="aui-searchbar" id="search">
			<div class="aui-searchbar-input aui-border-radius" tapmode onclick="doSearch()">
				<i class="aui-iconfont aui-icon-search"></i>
				<div class="aui-searchbar-input">
					<form action="javascript:search();">
						<input type="search" placeholder="请输入物料名称" id="search-input">
					</form>
				</div>
				<i class="aui-iconfont aui-icon-roundclosefill" tapmode onclick="clearInput()"></i>
			</div>
			<div class="aui-searchbar-cancel aui-text-info" tapmod onclick="cancelSearch()">取消</div>
		</div>
		<ul class="aui-list aui-list-in" id="mrlListUl" style="margin-top: 2.2rem">

		</ul>
	</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
	apiready = function () {
		search();
	};

	function doSearch() {
		$api.addCls($api.dom(".aui-searchbar"), "focus");
		$api.dom('.aui-searchbar-input input').focus();
	}

	function cancelSearch() {
		$api.removeCls($api.dom(".aui-searchbar.focus"), "focus");
		$api.val($api.byId("search-input"), '');
		$api.dom('.aui-searchbar-input input').blur();
	}

	function clearInput() {
		$api.val($api.byId("search-input"), '');
	}

	function search() {
		var content = $api.val($api.byId("search-input"));
		cancelSearch();

		var invoiceplancode = api.pageParam.invoiceplancode;
		var un = localStorage.getItem("un");
		var serverUrl = localStorage.getItem('serverUrl');
		var url = serverUrl + "/app/getMrlInvoiceplanByCode";
		var data = {
			values: {
				un: un,
				invoiceplancode: invoiceplancode,
				mrlCode: content,
			}
		};

		api.ajax({
			url: url,
			method: 'post',
			dataType: 'json',
			timeout: 300,
			returnAll: false,
			data: data
		}, function (ret, err) {
			if (ret) {
				var data = JSON.stringify(ret);
				var myobj = eval("(" + data + ")");
				if (myobj.code == '0') {
					var mydata = eval(myobj.list);
					var evaluation = doT.template($api.dom('#mrlTemp').innerHTML);
					$api.dom('#mrlListUl').innerHTML = evaluation(mydata);
				} else {
					api.toast({
						msg: myobj.message,
						duration: 3000
					});
				}
			}
		});
	}

	function setMrl(id, code, name) {
		api.closeWin();
        var nameR = api.pageParam.name;
        api.execScript({
            name: nameR,
            script: 'setMrl("' + id + '","' + code + '","' + name + '")'
        });
	}

	function closeWin(){
		api.closeWin();
	}
</script>

</html>